package com.yusysqdy.gulimall.search.controller;

import com.yusysqdy.gulimall.search.service.GulimallSearchService;
import com.yusysqdy.gulimall.search.vo.SearchParam;
import com.yusysqdy.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: gulimail
 * @contact: qindy0116@126.com
 * @author: Mr.DYQin
 * @create: 2021-01-18 11:39
 **/

@Controller
public class SearchController {

    @Autowired
    private GulimallSearchService gulimallSearchService;

    /**
     * 自动将页面提交过来的所有请求查询参数封装成指定的对象
     * @param searchParam
     * @param model
     * @param request
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request){

        // 获取路径原生的查询属性
        searchParam.set_queryString(request.getQueryString());
        // ES中检索到的结果 传递给页面
        SearchResult result = gulimallSearchService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }

}
